package java19_5_5.com.huweilong.about_vector;

public class Main2 {
    public static void main(String[] args) {
        Object lock = new Object();
        long n = 0;
        // 锁粒度过细
        while (true) {
            synchronized (lock) {
                n++;
            }
        }
    }

    // 经过 JVM 优化，可能变成下面的形式
    public static void main2(String[] args) {
        Object lock = new Object();
        long n = 0;
        // 锁粒度适当加粗，提升性能
        while (true) {
            synchronized (lock) {
                n++;
                n++;
                n++;
                n++;
                n++;
                n++;
            }
        }
    }
}
